//
//  InvitationViewController.m
//  NewPro
//
//  Created by 何荧红 on 2018/10/11.
//  Copyright © 2018 何荧红. All rights reserved.
//

#import "InvitationViewController.h"
#import "NSData+Base64.h"
#import "ShareStore.h"

@interface InvitationViewController ()
@property (nonatomic, strong) ViewHeader *SecView;
@property (nonatomic, strong) PushView *ShareView;

@end

@implementation InvitationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initCSS];
    [self loadData];
}
- (void)loadData{
    [[[ShareStore alloc]init] PostWithId:[UserDefaultsManager sharedInstance].user_id Success:^(NSDictionary * _Nonnull res) {
        if ([res[@"msg"] isEqualToString:@"success"]) {
            NSArray *arr = [res[@"data"][@"img"] componentsSeparatedByString:@","];
            NSData *data  = [[NSData alloc] initWithBase64EncodedString:arr[1]];
            NSDictionary *dic = @{@"img":data,@"customName":res[@"data"][@"custom"][@"realName"],@"phoneNumber":res[@"data"][@"custom"][@"phoneNumber"],@"recommendationCode":res[@"data"][@"custom"][@"recommendationCode"]};
            self.SecView.Invitationdic = dic;
            self.ShareView.scanQdata = data;
            self.ShareView.weburl = res[@"data"][@"url"];
            self.ShareView.name = res[@"data"][@"maintitle"];
            self.ShareView.subtitle = res[@"data"][@"subtitle"];
        }else{
            [self showMBPError:res[@"msg"]];
        }
    } Failure:^(NSError * _Nonnull error) {
        [self showMBPError:[HttpTool handleError:error]];
    }];
}
- (void)initCSS{
    
    [self setNavBarWithTitle:@"邀请合伙人"];
    
    self.SecView = [[ViewHeader alloc]initWithInvitationSecView];
    [self.view addSubview:_SecView];
    
    UIButton *SureButton = [[UIButton alloc]init];
    [SureButton addTarget:self action:@selector(toSure:) forControlEvents:UIControlEventTouchUpInside];
    SureButton.layer.masksToBounds = YES;
    SureButton.layer.cornerRadius = 5;
    SureButton.backgroundColor = [UIColor colorWithHexString:@"0CA6F0"];
    [SureButton setTitle:@"邀请合伙人加入" forState:UIControlStateNormal];
    SureButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:18];
    [SureButton setTitleColor:[UIColor colorWithHexString:@"ffffff"] forState:UIControlStateNormal];
    [self.view addSubview:SureButton];
    [SureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(self.SecView.mas_bottom).offset(41);
        make.width.mas_equalTo(SCREEN_WIDTH - 36);
        make.height.mas_equalTo(49);
    }];
    self.ShareView = [[PushView alloc]initWithShareView];
    [self.view addSubview:self.ShareView];
}
- (void)toSure:(UIButton *)button{
    [self.ShareView ViewPush:NO];
}

@end
